﻿using System;

namespace Communication.Message.Buffer
{
	// Token: 0x0200003B RID: 59
	internal class MessageBuffers
	{
		// Token: 0x060001A7 RID: 423 RVA: 0x000057B8 File Offset: 0x000039B8
		static MessageBuffers()
		{
			char[] array = "0123456789abcdef".ToCharArray();
			for (int i = 0; i < 256; i++)
			{
				MessageBuffers.HEXDUMP_TABLE[i << 1] = array[i >> 4 & 15];
				MessageBuffers.HEXDUMP_TABLE[(i << 1) + 1] = array[i & 15];
			}
		}

		//获取报文长度
		public static MessageBuffer Buffer(int capacity)
		{
			//大端模式
			return MessageBuffers.Buffer(ByteOrder.BIG_ENDIAN, capacity);
		}

		// Token: 0x060001A9 RID: 425 RVA: 0x00005825 File Offset: 0x00003A25
		public static MessageBuffer Buffer(ByteOrder endianness, int capacity)
		{
			if (endianness == ByteOrder.BIG_ENDIAN)
			{
				if (capacity == 0)
				{
					return MessageBuffers.EMPTY_BUFFER;
				}
				return new BigEndianHeapMessageBuffer(capacity);
			}
			else
			{
				if (endianness != ByteOrder.LITTLE_ENDIAN)
				{
					throw new ArgumentException("endianness");
				}
				if (capacity == 0)
				{
					return MessageBuffers.EMPTY_BUFFER;
				}
				return new LittleEndianHeapMessageBuffer(capacity);
			}
		}

		// Token: 0x060001AA RID: 426 RVA: 0x00005858 File Offset: 0x00003A58
		public static MessageBuffer DynamicBuffer()
		{
			return MessageBuffers.DynamicBuffer(ByteOrder.BIG_ENDIAN, 256);
		}

		// Token: 0x060001AB RID: 427 RVA: 0x00005865 File Offset: 0x00003A65
		public static MessageBuffer DynamicBuffer(MessageBufferFactory factory)
		{
			if (factory == null)
			{
				throw new ArgumentNullException("factory");
			}
			return new DynamicMessageBuffer(factory.GetDefaultOrder(), 256, factory);
		}

		// Token: 0x060001AC RID: 428 RVA: 0x00005886 File Offset: 0x00003A86
		public static MessageBuffer DynamicBuffer(int estimatedLength)
		{
			return MessageBuffers.DynamicBuffer(ByteOrder.BIG_ENDIAN, estimatedLength);
		}

		// Token: 0x060001AD RID: 429 RVA: 0x0000588F File Offset: 0x00003A8F
		public static MessageBuffer DynamicBuffer(ByteOrder endianness, int estimatedLength)
		{
			return new DynamicMessageBuffer(endianness, estimatedLength);
		}

		// Token: 0x060001AE RID: 430 RVA: 0x00005898 File Offset: 0x00003A98
		public static MessageBuffer DynamicBuffer(int estimatedLength, MessageBufferFactory factory)
		{
			if (factory == null)
			{
				throw new ArgumentNullException("factory");
			}
			return new DynamicMessageBuffer(factory.GetDefaultOrder(), estimatedLength, factory);
		}

		// Token: 0x060001AF RID: 431 RVA: 0x000058B5 File Offset: 0x00003AB5
		public static MessageBuffer DynamicBuffer(ByteOrder endianness, int estimatedLength, MessageBufferFactory factory)
		{
			return new DynamicMessageBuffer(endianness, estimatedLength, factory);
		}

		// Token: 0x060001B0 RID: 432 RVA: 0x000058BF File Offset: 0x00003ABF
		public static string HexDump(MessageBuffer buffer)
		{
			return MessageBuffers.HexDump(buffer, buffer.ReaderIndex(), buffer.ReadableBytes());
		}

		// Token: 0x060001B1 RID: 433 RVA: 0x000058D4 File Offset: 0x00003AD4
		public static string HexDump(MessageBuffer buffer, int fromIndex, int length)
		{
			if (length < 0)
			{
				throw new ArgumentException("length: " + length);
			}
			if (length == 0)
			{
				return "";
			}
			int num = fromIndex + length;
			char[] array = new char[length << 1];
			int i = fromIndex;
			int num2 = 0;
			while (i < num)
			{
				Array.Copy(MessageBuffers.HEXDUMP_TABLE, (int)buffer.GetByte(i) << 1, array, num2, 2);
				i++;
				num2 += 2;
			}
			return new string(array);
		}

		// Token: 0x060001B2 RID: 434 RVA: 0x00005940 File Offset: 0x00003B40
		public static bool Equals(MessageBuffer bufferA, MessageBuffer bufferB)
		{
			if (bufferA == null || bufferB == null)
			{
				return false;
			}
			int num = bufferA.ReadableBytes();
			if (num != bufferB.ReadableBytes())
			{
				return false;
			}
			int num2 = num;
			int num3 = bufferA.ReaderIndex();
			int num4 = bufferB.ReaderIndex();
			for (int i = num2; i > 0; i--)
			{
				if (bufferA.GetByte(num3) != bufferB.GetByte(num4))
				{
					return false;
				}
				num3++;
				num4++;
			}
			return true;
		}

		// Token: 0x0400006E RID: 110
		public static readonly MessageBuffer EMPTY_BUFFER = new BigEndianHeapMessageBuffer(0);

		// Token: 0x0400006F RID: 111
		private static readonly char[] HEXDUMP_TABLE = new char[1024];
	}
}
